// tags标签页
const homeTag = { path: '/home', name: 'Home', meta: { title: '首页' } }
const tags = {
  state: () => ({
    // tag标签页数组
    tagList: [homeTag],
  }),
  mutations: {
    setTagList(state, payload) {
      state.tagList = payload
      console.log('state.tagList=========', state.tagList)
    },
  },
  actions: {
    // 增加tag标签
    addTag({ state, commit }, payload) {
      const curIndex = state.tagList.findIndex(item => {
        return item.path === payload.path
      })
      let newList = [...state.tagList]
      if (curIndex === -1) {
        newList = [...state.tagList, payload]
      }
      commit('setTagList', newList)
    },
    deleteTag({ state, commit }, payload) {
      const curIndex = state.tagList.findIndex(item => {
        return item.path === payload.path
      })
      let newList = [...state.tagList]
      if (curIndex !== -1) {
        newList.splice(curIndex, 1)
      }
      commit('setTagList', newList)
    },
    // 清空tags
    clearTags({ commit }) {
      commit('setTagList', [homeTag])
    },
  },
}

export default tags
